<?php
    $title = '用户管理';
    include('./../head.php');
?>
<body class="container">

    <div class="row">
        <div class="col-12">
            <nav class="navbar navbar-dark bg-primary navbar navbar-expand-lg">
                <a class="navbar-brand" href="#">学生管理系统</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNavDropdown">
                    <ul class="navbar-nav">
                        <li class="nav-item active">
                            <a class="nav-link" href="#">首页 <span class="sr-only">(current)</span></a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">用户管理</a>
                        </li>
                    </ul>
                </div>
                <form class="form-inline my-2 my-lg-0">
                      <a>退出</a>
                </form>
            </nav>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <form>
                <div class="row mt-2">
                    <div class="col">
                        <input type="text" class="form-control" placeholder="用户名">
                    </div>
                    <div class="col">
                        <input type="text" class="form-control" placeholder="姓名">
                    </div>
                    <div class="col">
                        <button type="submit" class="btn btn-info">查询</button>
                    </div>
                </div>
            </form>
        </div>
        <hr>
        <div class="col-12 text-right">
            <a class="btn btn-sm btn-primary"><i class=""></i>新增</a>
        </div>
        <hr>
        <div class="col-12">

            <table class="table table-striped">
                <thead>
                    <tr>
                        <th scope="col">序号</th>
                        <th scope="col">姓名</th>
                        <th scope="col">用户名</th>
                        <th scope="col">角色</th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        include('./../user.php');
                        $page = 0;
                        if (isset($_GET['page'])) {
                            $page = (int) $_GET['page'];
                        }
                        
                        $userPage = User::page($page);

                        $users = $userPage->content;

                        foreach($users as $key => $user) {
                            echo '
                            <tr>
                                <th scope="row">' . ($userPage->number * $userPage->size + $key + 1) .'</th>
                                <td>' . $user['name'] . '</td>
                                <td>' . $user['username']. '</td>
                                <td>' . ($user['role'] === '0' ? '管理员' : '用户') . '</td>
                                <td>
                                    <a class="btn btn-outline-primary btn-sm">修改</a>
                                    <a class="btn btn-outline-danger btn-sm">删除</a>
                                </td>
                            </tr>
                            ';
                        }
                    ?>
                    
                </tbody>
            </table>
            <div class="row">
                <div class="offset-4 col-4">
                    <nav aria-label="Page navigation">
                        <ul class="pagination">
                            <li class="page-item">
                                <a class="page-link" href="?page=0" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            <?php
                                for ($i = 0; $i < $userPage->totalPage; $i++) {
                                    echo '
                                    <li class="page-item' . 
                                        ($userPage->number === $i ? ' active' : '')
                                    . '"><a class="page-link" href="?page=' . $i . '">'
                                        . ($i + 1) .
                                    '</a></li>
                                    ';
                                }
                            ?>
                            <li class="page-item">
                                <a class="page-link" href="?page=<? echo $userPage->totalPage - 1; ?>" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
         
         
        </div>
    </div>
</body>
